package execute

import (
	"crypto/tls"
	"net/http"
	"time"
)

type NetWorkConfig struct {
	TransPortConfig TransPortConfig
	HttpConfig      HttpConfig
}
type DefaultNetWorkConfig struct {
}

func (DefaultNetWorkConfig) GetNetWorkConfig() *NetWorkConfig {
	return &NetWorkConfig{
		TransPortConfig: TransPortConfig{
			DialTimeOut:           time.Second * 3,
			ReadTimeOut:           time.Second * 3,
			WriteTimeOut:          time.Second * 3,
			ConnTimeOut:           time.Second * 3,
			IdleConnTimeout:       time.Second * 10,
			ExpectContinueTimeout: time.Second * 1,
			TLSHandshakeTimeout:   time.Second * 2,
			DisableKeepAlives:     true,
			TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
		},
		HttpConfig: HttpConfig{
			Timeout: time.Second * 10,
		},
	}
}

func GetSycTransportSetting() TransPortConfig {

	sysTransport := http.DefaultTransport.(*http.Transport)

	return TransPortConfig{
		DialTimeOut:           30 * time.Second,
		DialKeepAlive:         30 * time.Second,
		ReadTimeOut:           30 * time.Second,
		WriteTimeOut:          30 * time.Second,
		ConnTimeOut:           30 * time.Second,
		IdleConnTimeout:       sysTransport.IdleConnTimeout,
		ExpectContinueTimeout: sysTransport.ExpectContinueTimeout,
		TLSHandshakeTimeout:   sysTransport.TLSHandshakeTimeout,
		DisableKeepAlives:     sysTransport.DisableKeepAlives,
		TLSClientConfig:       sysTransport.TLSClientConfig,
	}
}

type TransPortConfig struct {
	DialTimeOut           time.Duration
	DialKeepAlive         time.Duration
	ReadTimeOut           time.Duration
	WriteTimeOut          time.Duration
	ConnTimeOut           time.Duration
	IdleConnTimeout       time.Duration
	ExpectContinueTimeout time.Duration
	TLSHandshakeTimeout   time.Duration
	DisableKeepAlives     bool
	TLSClientConfig       *tls.Config
}

type HttpConfig struct {
	Timeout time.Duration
}
